﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NATP2P.UPNP;
namespace UPnPController
{
    public partial class Form1 : Form
    {
        NATUPNP UPnPHandler=new NATUPNP();
        Add add = new Add();
        public Form1()
        {
            InitializeComponent();
          
           //UPnPRefresh();
        }

        private void UPnPRefresh()
        {
            if (UPnPHandler.Discovery())
            {
                listView1.Items.Clear();
                foreach (var item in UPnPHandler.GetGenericPortMappingEntry())
                {
                    ListViewItem row = new ListViewItem(item.NewInternalPort);
                   
                    row.SubItems.Add(item.NewInternalClient);
                    row.SubItems.Add(item.NewExternalPort);
                    row.SubItems.Add(item.NewProtocol);
                    row.SubItems.Add(item.NewPortMappingDescription);
                    row.SubItems.Add((1==int.Parse(item.NewEnabled)).ToString());
                    listView1.Items.Add(row);
 
                }
                label2.Text = UPnPHandler.GetExternalIP().ToString();
                toolStripStatusLabel1.Text = "Ready";
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (add.IsDisposed)
            {
                add = new Add();
            }
            add.Owner = this;
            add.UPnPHandler = UPnPHandler;
            add.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UPnPRefresh();
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

       
    }
}
